package com.ruoyi.activiti.bpmnparse.x6translator;

import com.ruoyi.activiti.bpmnparse.Translator;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class X6UserTaskTranslator extends Translator {
    public final static String MULTI_TASK = "1";
    private List<Map<String,Object>> x6ListMap;
    private final String type = "userTask";
    public X6UserTaskTranslator(List<Map<String,Object>> x6ListMap){
        this.x6ListMap = x6ListMap;
    }
    public String getTaskType(){
        return type;
    }
    @Override
    public Map<String, Object> translate(Map<String, Object> sourceMap) {
        Map<String, Object> dataMap = (Map<String, Object>) sourceMap.get("data");
        Map<String, Object> bpmnMap = new HashMap<>();
        String id = (String) dataMap.get("id");
        String name = (String) dataMap.get("label");
        String isMulti = (String) dataMap.get("isMulti");
        if(MULTI_TASK.equals(isMulti)) {
            MultiUserTaskTranslator multiUserTaskTranslator = new MultiUserTaskTranslator(x6ListMap);
            return multiUserTaskTranslator.translate(sourceMap);
        } else {
            String candidateGroups = (String) dataMap.get("candidateGroups");
            String assignee = (String) dataMap.get("assignee");
            bpmnMap.put(Translator.BPMN_TYPE, type);
            bpmnMap.put(Translator.BPMN_ID, id);
            bpmnMap.put(Translator.BPMN_NAME, name);
            bpmnMap.put(Translator.BPMN_GROUP, candidateGroups);
            bpmnMap.put(Translator.BPMN_ASSIGNEE, assignee);
        }
        return bpmnMap;
    }

}
